/**  smsh1.c  small-shell version 1
 **		first really useful version after prompting shell
 **		this one parses the command line into strings
 **		uses fork, exec, wait, and ignores signals
 **/

#include	<stdio.h>
#include	<stdlib.h>
#include	<unistd.h>
#include	<signal.h>
#include	"smsh.h"

#define	DFL_PROMPT	"mgl> "

int main()
{
	char	*cmdline, *prompt, **arglist;
	int	result;
	void	setup();
	int argpos=0;
	prompt = DFL_PROMPT ;
	setup();

	while ( (cmdline = next_cmd(prompt, stdin)) != NULL ){
		argpos =0;
		if ( (arglist = splitline(cmdline)) != NULL  ){
			while (*(arglist + argpos) !=NULL)  //print arglist param.
			{
				printf("arglist is %s ",*(arglist+argpos));
				argpos++;
				/* code */
			}
			printf("\n");
			fflush(stdout);

			result = execute(arglist);
			freelist(arglist);
		}
		free(cmdline);
	}
	return 0;
}

void setup()
/*
 * purpose: initialize shell
 * returns: nothing. calls fatal() if trouble
 */
{
	signal(SIGINT,  SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
}

void fatal(char *s1, char *s2, int n)
{
	fprintf(stderr,"Error: %s,%s\n", s1, s2);
	exit(n);
}

